import type {RootStackParamList} from './typing';
import type {NavigationContainerRef} from '@react-navigation/native';

import * as React from 'react';

// eslint-disable-next-line unicorn/prevent-abbreviations
export const navigationRef = React.createRef<NavigationContainerRef<RootStackParamList>>();

export function navigate<RouteName extends keyof RootStackParamList>(
  name: RouteName,
  parameters?: RootStackParamList[RouteName],
) {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  navigationRef.current?.navigate(name as any, parameters);
}

export function reset() {
  navigationRef.current?.reset({
    index: 0,
    routes: [{name: 'LOGIN'}],
  });
}
